<?php

namespace App\Modules\Admin\Http\Controllers\Auth;

use App\Http\Controllers\BaseController;
use App\Modules\Admin\Services\AdminMenuService;
use Illuminate\Http\Request;

class AdminMenuController extends BaseController
{
    public function __construct(AdminMenuService $adminMenuService)
    {
        $this->middleware('check.adminLogin')->except('index');

        $this->adminMenuService = $adminMenuService;
    }

    public function index()
    {
        $param = [];
        $data = $this->adminMenuService->getList($param);

        return $this->response->success($data);
    }

    public function show(Request $request)
    {
        $id = $request->input('id');
        $result = $this->adminMenuService->getInfo($id);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'parent_uid' => 'require',
            'title|标题' => 'require',
            'path|路径' => 'require',
            'icon|图标' => 'noRequire',
            'permission|权限标识' => 'noRequire',
            'sort|排序' => 'noRequire|number|default:0',
            'type|类型' => 'noRequire|number|default:1',
        ]);

        $result = $this->adminMenuService->add($param);

        return $this->response->success($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = [];
        $result = $this->adminMenuService->update($param, $id);

        return $this->response->success($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->adminMenuService->delete($id);

        return $this->response->success($result);
    }

    public function roleMenu(Request $request)
    {

        $adminUid = $request->user()->admin_uid;
        $result = $this->adminMenuService->roleMenu($adminUid);

        return $this->response->success($result);

    }
}
